import React, { useState, useContext } from "react";
import ajax from "./axios";
import { Toast } from "antd-mobile";
import { useHistory } from "react-router-dom";
import { Context } from "./App";
const login_btn = "https://lcz-quna.oss-cn-beijing.aliyuncs.com/img/login_btn.png"
function Home() {
  // xiaoyingwu@fintopia.tech
  //yanbowei@fintopia.tech
  const history = useHistory();
  const { n, setN } = useContext(Context);
  const [param, setparam] = useState({
    employeeNo: "",
  });
  const loginFun = () => {
    if (!param.employeeNo) {
      Toast.show({
        position: "top",
        content: "请输入手机号！",
      });
    } else {
      ajax("post", "/oauth/login",{},{
        ad:param.employeeNo
      }).then((res) => {
        if (res.code == 0) {
          if (res.data) {
            localStorage.setItem("USER_DATA", JSON.stringify(res.data));
            history.replace("/home");
          } else {
            Toast.show({
              position: "top",
              content: "请QT员工关爱热线",
            });
          }

        } else {
          Toast.show({
            position: "top",
            content: "请QT员工关爱热线",
          });
        }
      });

    }
  };
  return (
    <div className="login">
      <div>
        <div className="input_all">
          <div className="login_name">
            <input
              onChange={(e) => {
                setparam({ employeeNo: e.target.value });
              }}
              value={param.employeeNo}
              placeholder={"请输入QT账号（如Q123456）"}
            />
          </div>
          <div className="login_button">
            <img
              onClick={() => {
                loginFun();
              }}
              src={login_btn}
            />
          </div>
        </div>
      </div>
    </div>
  );
}

export default Home;
